package com.j.lemon.learn.clickhouse;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson.JSON;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @author lijunjun
 */
public class CkTimeZoneTest {
    public static void main(String[] args) throws SQLException {
        String driverClassName = "ru.yandex.clickhouse.ClickHouseDriver";
        String url = "jdbc:clickhouse://10.28.149.247:38123/default";
        String url1 = "jdbc:clickhouse://10.28.149.247:18123/default";
        String userName = "audit4a";
        String password = "rryzggTR";
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(userName);
        dataSource.setPassword(password);
        dataSource.setTestWhileIdle(true);
        dataSource.setMaxActive(100);
        dataSource.setMaxWait(60000);
        dataSource.setTestOnBorrow(false);

        DruidDataSource dataSource1 = new DruidDataSource();
        dataSource1.setDriverClassName(driverClassName);
        dataSource1.setUrl(url1);
        dataSource1.setUsername(userName);
        dataSource1.setPassword(password);
        dataSource1.setTestWhileIdle(true);
        dataSource1.setMaxActive(100);
        dataSource1.setMaxWait(60000);
        dataSource1.setTestOnBorrow(false);
        long id = 124;
//        Connection connection = dataSource.getConnection();
//        connection.setAutoCommit(false);
//        String sql = "insert into behavior_log_new (id,userid,btag,cate,brand,opt_time) values (?,?,?,?,?,?)";
//        PreparedStatement ps = connection.prepareStatement(sql);
//        String[] line = new String[]{"123","456","789","000"};
//        ps.setLong(1, id);
//        ps.setInt(2, Integer.parseInt(line[0]));
//        ps.setString(3, line[1]);
//        ps.setString(4, line[2]);
//        ps.setString(5, line[3]);
//        ps.setString(6, "2022-03-04 13:13:13");
//        ps.addBatch();
//        ps.executeBatch();
//        connection.commit();
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource1);
        String querySql = "select * from behavior_log_new_all where id = 124";
        List<Map<String, Object>> map = jdbcTemplate.queryForList(querySql);
        System.out.println(JSON.toJSONString(map));

    }
}
